package com.satan.novel.author.manager.feign;

import com.satan.novel.author.dto.AuthorInfoDto;
import com.satan.novel.author.manager.cache.AuthorInfoCacheManager;
import com.satan.novel.book.dto.req.*;
import com.satan.novel.book.dto.resp.BookChapterRespDto;
import com.satan.novel.book.dto.resp.BookInfoRespDto;
import com.satan.novel.book.dto.resp.ChapterContentRespDto;
import com.satan.novel.book.feign.BookFeign;
import com.satan.novel.common.auth.UserHolder;
import com.satan.novel.common.resp.PageRespDto;
import com.satan.novel.common.resp.RestResp;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * @Author: Demon
 * @Date: 2024/2/3 17:15
 * @Description: 小说微服务调用 Feign 客户端管理
 **/
@Component
@RequiredArgsConstructor
public class BookFeignManager {
    private final BookFeign bookFeign;
    private final AuthorInfoCacheManager authorInfoCacheManager;

    public RestResp<PageRespDto<BookInfoRespDto>> listPublishBooks(BookPageReqDto dto) {
        authorInfoCacheManager.getAuthor(UserHolder.getUserId());
        return bookFeign.listPublishBooks(dto);
    }

    public RestResp<Void> publishBook(BookAddReqDto dto) {
        AuthorInfoDto author = authorInfoCacheManager.getAuthor(UserHolder.getUserId());
        dto.setAuthorId(author.getId());
        dto.setPenName(author.getPenName());
        return bookFeign.publishBook(dto);
    }

    public RestResp<Void> publishBookChapter(ChapterAddReqDto dto) {
        return bookFeign.publishBookChapter(dto);
    }

    public RestResp<PageRespDto<BookChapterRespDto>> listPublishBookChapters(ChapterPageReqDto dto) {
        return bookFeign.listPublishBookChapters(dto);
    }

    public RestResp<Void> deleteBookChapter(Long chapterId) {
        return bookFeign.deleteBookChapter(chapterId);
    }

    public RestResp<Void> updateBookChapter(Long chapterId, ChapterUpdateReqDto dto) {
        return bookFeign.updateBookChapter(chapterId, dto);
    }

    public RestResp<ChapterContentRespDto> getBookChapter(Long chapterId) {
        return bookFeign.getBookChapter(chapterId);
    }
}
